package com.tairan.chapter.nacos.config.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.tairan.chapter.nacos.config.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/config")
@EnableConfigurationProperties(User.class)
public class ConfigController {

    @NacosValue(value = "${config.useLocalCache:false}", autoRefreshed = true)
    private boolean useLocalCache;

    @Value(value = "${config.litairan:default}")
    private String litairan;

    @Autowired
    private User user;

    @RequestMapping("/get")
    public String get() {
        return useLocalCache + ":" + litairan;
    }

    @RequestMapping("/user")
    public User user() {
        return user;
    }
}
